import { getSearchQuery } from '@/utils';
import { useAtom } from 'jotai';
import React, { useEffect } from 'react';
import { useParams } from 'react-router-dom';
import { AllComponents } from '../Demo/datas';
import { comDataAtom } from '../Demo/models';
import styles from './index.module.less';

// 渲染引擎处理区
const Index = () => {
  const [comData, setComData] = useAtom(comDataAtom);

  useEffect(() => {
    const data = getSearchQuery('comData');
    if (data) {
      setComData(JSON.parse(data as any));
    }
  }, [setComData]);
  console.log('comData', comData);

  return (
    <div className={styles.boxWrap}>
      {!comData?.length && <div>空</div>}
      {comData?.map?.((item, i) => {
        const Com = AllComponents[item.type];
        return <Com {...item} key={`${item.type + i}`} />;
      })}
    </div>
  );
};

export default Index;
